package com.qf.flash.ui.circle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.qf.flash.R;
import com.qf.flashlib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HotListActivity extends BaseActivity {
    @BindView(R.id.tv_top_back)
    TextView tvTopBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.tab)
    TabLayout tab;
    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    @BindView(R.id.vp_hot)
    ViewPager mViewPager;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_hot_list;
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, HotListActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void initViewAndData() {
        tvTopTitle.setText("热门榜");
        initTab();
    }

    private void initTab() {
        tab.addTab(tab.newTab().setText("热门剧本榜"));
        tab.addTab(tab.newTab().setText("热门主题榜"));
        fragments.add(HotFragment.newInstance("1"));//推荐
        fragments.add(HotFragment.newInstance("2"));//推荐
        titles.add("热门剧本榜");
        titles.add("热门主题榜");

        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return titles.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles.get(position);
            }
        });

        tab.setupWithViewPager(mViewPager);
        mViewPager.setOffscreenPageLimit(2);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.tv_top_back)
    public void onViewClicked() {
        finish();
    }
}
